package com.ruiyi.careryun.service.user.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.stereotype.Service;

import com.ruiyi.careryun.beans.common.PageRequest;
import com.ruiyi.careryun.beans.user.UserInfo;
import com.ruiyi.careryun.common.PageModel;
import com.ruiyi.careryun.mapper.user.UserInfoMapper;
import com.ruiyi.careryun.service.user.UserInfoService;

/**
 * @Description: TODO
 * @date: 2016年7月22日 下午3:51:56
 * @author: zengt
 * @version: 1.0
 */
@Service
public class UserInfoServiceImpl implements UserInfoService {
	@Autowired
	UserInfoMapper userInfoMapper;
	@Autowired
	MongoOperations mongo;

	@Override
	public Integer add(UserInfo user) throws Exception {
		return userInfoMapper.add(user);
	}

	@Override
	public PageModel<UserInfo> getListByPage(PageRequest pageRequest) {
		List<UserInfo> list = userInfoMapper.getListByPage(pageRequest);
		return new PageModel<>(pageRequest.getTotalCount(), list);
	}

	@Override
	public UserInfo getUserByName(String username) {
		return userInfoMapper.getUserByName(username);
	}

	@Override
	public List<String> getAuthorityByUserId(Integer userId) {
		return userInfoMapper.getAuthorityByUserId(userId);
	}

	@Override
	public long getCount() {
		long userCount = mongo.getCollection("user").count();
		return userCount;
	}

}
